#ifndef __SOC_MISC_H__
#define __SOC_MISC_H__


#include "soc_misc_impl.h"
#include "soc_comm.h"


void SOC_SetCpuFrequency(uint32_t freq);
uint32_t SOC_GetCpuFrequency();

void SOC_Delay(uint32_t ms);
uint32_t SOC_GetCurrentMilliseconds(void);

char* SOC_GetCPUID();
void SOC_CpuReset();

void MiscIncTickMs(void);

#define TIME_EXEC_VAR(st, ms) do{\
    uint32_t val = SOC_GetCurrentMilliseconds();\
    if(((uint32_t)(val - st)) < ms){ \
        return;\
    }\
    st = val;\
}\
while(0)

#define TIME_EXEC(ms) do{\
    static uint32_t st = (0); \
    TIME_EXEC_VAR(st, ms); \
}\
while(0)


#define TIME_EXEC_CALL_VAR(st, ms, caller) do{\
    uint32_t val = SOC_GetCurrentMilliseconds();\
    if(((uint32_t)(val - st)) >= ms){ \
        caller;\
        st = val;\
    }\
}\
while(0)

#define TIME_EXEC_CALL(ms, caller) do{\
    static uint32_t st = (0); \
    TIME_EXEC_CALL_VAR(st, ms, caller); \
}\
while(0)


#endif 